package pers.vic.blog.module.api.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.vic.blog.module.api.model.BlogTag;
import pers.vic.blog.module.api.service.BlogTagService;
import pers.vic.boot.base.controller.BaseController;
import pers.vic.boot.base.model.BaseResponse;
import pers.vic.boot.base.vo.Select2VO;
import pers.vic.boot.util.CommonUtils;

import java.util.List;

/**
 * @author Vic.xu
 * @description:标签表 控制层
 * @date: 2020-05-08 09:38
 */
@RestController
@RequestMapping("/blog/tag")
public class BlogTagController extends BaseController<BlogTagService, BlogTag> {

    /**
     * 全部的标签
     */
    @RequestMapping(value = "all")
    public BaseResponse<List<Select2VO>> all() {
        BlogTag lookup = new BlogTag();
        lookup.setEnable(true);
        List<BlogTag> list = service.list(lookup);
        List<Select2VO> result = CommonUtils.listFilter(list, tag -> new Select2VO(tag.getId(), tag.getName()));
        return BaseResponse.success(result);
    }
}
